package org.uniview.common.service.transaction;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * Describe a transaction manager impelemention, which integrates 
 * with iBatis framework.
 * @author James Gao
 * @version 1.0 2007-1-10
 */
public class SqlMapTransactionManager implements TransactionManager {

	/**
	 * iBatis sql map client instance.
	 */
	private SqlMapClient txManager;
	
	/**
	 * Create a transaction manager by iBatis sql map client.
	 */
	public SqlMapTransactionManager(SqlMapClient txManager) {
		this.txManager = txManager;
	}

	/**
	 * @see org.uniview.common.service.transaction.TransactionManager#startTransaction()
	 */
	public void startTransaction() throws TransactionException{
		try {
			txManager.startTransaction();
		} catch (Exception e) {
			throw new TransactionException(1,e);
		}
	}

	/**
	 * @see org.uniview.common.service.transaction.TransactionManager#commitTransaction()
	 */
	public void commitTransaction() {
		try {
			txManager.commitTransaction();
		} catch (Exception e) {
			throw new TransactionException(1,e);
		}
	}

	/**
	 * @see org.uniview.common.service.transaction.TransactionManager#endTransaction()
	 */
	public void endTransaction() {
		try {
			txManager.endTransaction();
		} catch (Exception e) {
			throw new TransactionException(1,e);
		}
	}

}
